﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Acoris.Document
{
    using Acoris.Text;
    using Acoris.Media;
    using Acoris.Foundation;

    /// <summary>
    /// 表示字体样式
    /// </summary>
    public sealed class TextFormat:IContentFormat
    {
        /// <summary>
        /// 获取或设置字形边框颜色
        /// </summary>
        public Brush Stroke { get; set; }

        /// <summary>
        /// 获取或设置字形填充色
        /// </summary>
        public Brush Fill { get; set; } = new SolidColorBrush(new Color(0,0,0));

        /// <summary>
        /// 获取或设置水平对齐方式
        /// </summary>
        public HorizontalAlignment HorizontalAlignment { get; set; } = HorizontalAlignment.Left;

        /// <summary>
        /// 获取或设置垂直对齐方式
        /// </summary>
        public VerticalAlignment VerticalAlignment { get; set; } = VerticalAlignment.Top;

        /// <summary>
        /// 获取或设置字体
        /// </summary>
        public string FontFamily { get; set; } = "Segoe UI";

        /// <summary>
        /// 获取或设置字号大小
        /// </summary>
        public float FontSize { get; set; } = 15;

        /// <summary>
        /// 获取或设置字体宽度
        /// </summary>
        public float FontWeight { get; set; }

        /// <summary>
        /// 获取或设置制表符的缩进量
        /// </summary>
        public float TabStopIncreament { get; set; } = 4F;

        /// <summary>
        /// 获取或设置行距
        /// </summary>
        public float Linespacing { get; set; } = 1;

        /// <summary>
        /// 获取或设置一个值，该值指示顶部到行基线的距离（推荐为80%）
        /// </summary>
        public float LinespacingBaseline { get; set; } = .8f;

        #region Override

        /// <summary>
        /// 获取与当前对象等价的字符串形式
        /// </summary>
        /// <returns>返回与当前对象等价的字符串形式</returns>
        public override string ToString()
        {
            return base.ToString();
        }

        /// <summary>
        /// 获取当前对象与指定对象之间的等价性
        /// </summary>
        /// <param name="obj">指定要比较的对象</param>
        /// <returns>如果两个对象之间等价则返回true，否则返回false</returns>
        public override bool Equals(object obj)
        {
            if(obj is TextFormat textFormat) {
                return textFormat == this;
            }
            return false;
        }

        /// <summary>
        /// 获取当前对象的哈希值
        /// </summary>
        /// <returns>返回当前对象的哈希值</returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        #endregion

        #region operator == / !=

        public static bool operator ==(TextFormat x,TextFormat y)
        {
            return x.Fill == y.Fill &&
                   x.FontFamily == y.FontFamily &&
                   x.FontSize == y.FontSize &&
                   x.FontWeight == y.FontWeight &&
                   x.HorizontalAlignment == y.HorizontalAlignment &&
                   x.Linespacing == y.Linespacing &&
                   x.LinespacingBaseline == y.LinespacingBaseline &&
                   x.Stroke == y.Stroke &&
                   x.TabStopIncreament == y.TabStopIncreament &&
                   x.VerticalAlignment == y.VerticalAlignment;
        }

        public static bool operator !=(TextFormat x,TextFormat y)
        {
            return x.Fill != y.Fill ||
                   x.FontFamily != y.FontFamily ||
                   x.FontSize !=y.FontSize ||
                   x.FontWeight !=y.FontWeight ||
                   x.HorizontalAlignment !=y.HorizontalAlignment ||
                   x.Linespacing !=y.Linespacing ||
                   x.LinespacingBaseline !=y.LinespacingBaseline ||
                   x.Stroke !=y.Stroke ||
                   x.TabStopIncreament !=y.TabStopIncreament ||
                   x.VerticalAlignment !=y.VerticalAlignment;
        }

        #endregion
    }
}
